﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UCore;

namespace Twin {
    public partial class frmRdRec : Form {
        
        public string GeneratedString { get; private set; }
        private string[] arg;
        private string args;

        private int INST_BITS = 0;
        private int INST_OP = 1;            //OP_RD_REC, [cmfg], 180305073F0A[dt]
        private int INST_CMFG = 2;
        private int INST_DT = 3;

        private XPort xport = new XPort();


        public frmRdRec(XPort xport, string content) {  //OP_RD_REC, [cmfg], 180305073F0A[dt]
            InitializeComponent();

            GeneratedString = content;
            this.xport = xport;

            //dgvEdit
            //dgvInstant.ColumnHeadersVisible = false;
            //dgvInstant.AllowUserToAddRows = false;
            // 为DataGridView的MouseClick事件添加事件处理器
            //dgvInstant.MouseClick += dgvInstant_MouseClick;

            arg = content.Split(',');

            arg[INST_CMFG] = UI.init_cmbCmfg(cmbCmfg, arg[INST_CMFG]);
            //UI.init_cmbCom(cmbCom, Ini.defaultPort);

            string sDT = Common.RemoveBracketedContent(arg[INST_DT]);
            
            if (sDT.Equals("")) return;
            //int iFmt = Convert.ToInt32(s, 16);

            //init_cmbIFmt(iFmt);
            //UI.init_listEls(listEls);
            //init_dgvInstant(arg[INST_INSTANT]);

            //inst[INST_AREA_SN] = (Twin.TConsole.SnFile++).ToString("x");
            
        }


        private void frmRdRec_Load(object sender, EventArgs e) {
            this.TopMost = true;
            this.FormBorderStyle = FormBorderStyle.FixedSingle; // 设置窗体边框样式为固定单线框
            this.MaximizeBox = false;   // 移除最大化按钮
            this.MinimizeBox = false;   // 禁止调整大小

            TConsole.PositionFormAtTopRight(this);

            // 设置控件显示自定义格式的日期和时间
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm:ss";
            dateTimePicker1.ShowUpDown = true;
        }


        private void cmbCmfg_SelectedIndexChanged(object sender, EventArgs e) {
            arg[INST_CMFG] = cmbCmfg.SelectedIndex.ToString();
            if (arg[INST_CMFG].Equals("空")) {
                arg[INST_CMFG] = "";
            }
        }


        private void cmbCmfg_SelectedIndexChanged_1(object sender, EventArgs e) {
            arg[INST_CMFG] = cmbCmfg.SelectedItem.ToString();
            if (arg[INST_CMFG].Equals("空")) {
                arg[INST_CMFG] = "";
            }
        }


        private void btnSend_Click_1(object sender, EventArgs e) {      //OP_RD_REC, [cmfg], 180305073F0A[dt]
            arg[INST_DT] = Common.hexYYMMDDHHmmSS(dateTimePicker1.Value);
            //
            args = arg[INST_BITS] + "," + arg[INST_OP] + "," + arg[INST_CMFG] + "," + arg[INST_DT];
            
            //int iPort = int.Parse(cmbCom.Text.Replace("com", "")) - 1;
            CInfo cInfo = new CInfo();

            cInfo.sOpArgs = args;
            string wr_kvs = "";
            TConsole.sendAsProtocol(xport, ref cInfo, wr_kvs, "cobra");
        }

        private void btnSend_Click(object sender, EventArgs e) {

        }
    }
}
